package com.example.controller.admin;

import com.example.dto.StoreDTO;
import com.example.dto.StorePageQueryDTO;
import com.example.dto.UserDTO;
import com.example.entity.Inventory;
import com.example.entity.Store;
import com.example.entity.User;
import com.example.result.PageResult;
import com.example.result.Result;
import com.example.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 1. @ClassDescription:
 * 2. @author: Z
 * 3. @date: 2024年03月21日 16:53
 */
@RestController
@RequestMapping("/admin/store")
@Slf4j
@Api(tags = "管理页面商店相关接口")
public class StoreController {

    @Autowired
    private StoreService storeService;


    @PostMapping()
    @ApiOperation("添加商店")
    public Result<Store> addStore(@RequestBody StoreDTO storeDTO){
        log.info("新增商店:{}",storeDTO);
        Store store = storeService.insert(storeDTO);
        if(store!=null)
            return Result.success(store);
        else
            return Result.error("添加失败，商店名重复");
    }

    @PutMapping
    @ApiOperation("编辑商店信息") //也可以用来更改上商店的营业状态
    public Result<Store> update(@RequestBody StoreDTO storeDTO){
        log.info("编辑员工信息:{}",storeDTO);
        Store store = storeService.update(storeDTO);
        if(store == null){
            return Result.error("商店名重复");
        }else
            return Result.success(store);
    }


    @GetMapping("/{id}")
    @ApiOperation("查询店铺")
    public Result<Store> queryById(@PathVariable Long id){
        log.info("查询店铺：{}",id);
        return Result.success(storeService.queryById(id));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询商店")
    public Result<PageResult> page(StorePageQueryDTO storePageQueryDTO){
        log.info("查询店铺：{}",storePageQueryDTO);
        PageResult pageResult = storeService.page(storePageQueryDTO);
        return Result.success(pageResult);
    }


}
